// DBVariable.cpp: implementation of the DBVariable class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DBVariable.h"
#include "PropertyVisitor.h"
#include "SimpleExpression.h"
#include "ModelObject.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

namespace PropertySystem
{
	UE_IMPLEMENT_DYNAMIC(DBVariable, PropertyVariable);
	
	DBVariable::DBVariable()
	{
		
	}
	
	DBVariable::~DBVariable()
	{
		
	}

	void DBVariable::InitValue()
	{
		if(GetOwner() == NULL || this->Default().IsEmpty() || m_bIsInitState)
			return;

		m_bIsInitState = TRUE;
		SimpleExpression expr(this->Default(), this->GetOwner()->GetPropertyStack());

		*static_cast<Variable*>(this) = (CString)expr.Caculate();
		m_bIsInitState = FALSE;
	}

	PropertyVariable* DBVariable::Clone()
	{
		DBVariable* pVariable = new DBVariable;
		ASSERT(pVariable);

		this->CopyPropertyData(*pVariable, *this);
		pVariable->m_strPropertyTable = m_strPropertyTable;
		pVariable->m_strPropertyField = m_strPropertyField;

		return pVariable;
	}

	BOOL DBVariable::Accept(PropertyVisitor& visitor)
	{
		return visitor.Visit(this);
	}
};
